package cn.remex.core.net;

import cn.remex.core.exception.NetException;
import cn.remex.core.exception.ServiceCode;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;

/**
 * 名称：
 * 缩写：
 * 用途：
 * Created by yangy on 2016/8/26 0026.
 */
public class HttpConsumerEntity {
	private HttpURLConnection httpURLConnection;

	public HttpConsumerEntity(HttpURLConnection httpURLConnection) {
		this.httpURLConnection = httpURLConnection;
	}

	public InputStream getInputStream() {
		try {
			return new BufferedInputStream(httpURLConnection.getInputStream());
		} catch (IOException e) {
			throw new NetException(ServiceCode.FAIL, "HttpURLConnection,打开InputStream流失败", e);
		}
	}

	public OutputStream getOutputStream() {
		try {
			return new BufferedOutputStream(httpURLConnection.getOutputStream());
		} catch (IOException e) {
			throw new NetException(ServiceCode.FAIL, "HttpURLConnection,打开OutputStream流失败", e);
		}
	}

	public String getContentType() {
		return httpURLConnection.getContentType();
	}
}
